package com.railway.service.impl;

import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Set;

import com.railway.bean.Expenditures;
import com.railway.bean.Integra;
import com.railway.bean.IntegraDetailed;
import com.railway.bean.Page;
import com.railway.bean.Revenue;
import com.railway.dao.IntegraDao;
import com.railway.dao.OrderDao;
import com.railway.dao.impl.IntegraDaoImpl;
import com.railway.dao.impl.OrderDaoImpl;
import com.railway.service.IntegraService;

public class IntegraServiceImpl implements IntegraService{

	IntegraDao itd = new IntegraDaoImpl();
	OrderDao od = new OrderDaoImpl();
	
	@Override
	public Map selectIntegra(Map<String, String[]> map) {
		Set<String> keys = map.keySet();
		int user_id = 0;
		for (String key : keys) {
			if("user_id".equals(key) && "".equals(map.get(key)[0])) {
				user_id = Integer.parseInt(map.get(key)[0]);
			}
		}
		Map m = new HashMap();
		Integra integra = itd.selectIntegra(user_id);
		integra.setIntegraDetaileds(itd.selectIntegraDetaileds(integra.getIntegra_id()));
		itd.updateIntegra(integra.getIntegra_id(), integra.getCountImtegral(), integra.getIncrease_or_decrease());
		m.put("integra", integra);
		return m;
	}
	

	@Override
	public Page<List<IntegraDetailed>> selectIntegtraDetailed(Map<String, String[]> map) {
		Set<String> keys = map.keySet();
		int PageNum = 1;
		int PageSize = 5;
		int integra_id = 0;
		int order_id = 0;
		List<IntegraDetailed> integraDetaileds = itd.selectIntegraDetailedsByTime(Integer.parseInt(map.get("integra_id")[0]),map.get("give_or_take")[0],map.get("Startingtime ")[0],map.get("Endtime")[0]);
		for (IntegraDetailed integraDetailed : integraDetaileds) {
			integraDetailed.setOrder(od.selectOrder(integraDetailed.getOrder_id()));
		}
		Page page = new Page<IntegraDetailed>(integraDetaileds,PageNum,PageSize,integraDetaileds.size());
		return page;
	}
	
}
